package com.qing.springcloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.net.InetSocketAddress;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;

@SpringBootApplication
@EnableDiscoveryClient
@EnableAspectJAutoProxy
@EnableWebMvc
public class ChatApplication implements CommandLineRunner {

    @Autowired
    private ServerBootstrap serverBootstrap;

    @Autowired
    private InetSocketAddress tcpSocketAddress;

    public static void main(String[] args) {
        SpringApplication.run(ChatApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        Channel serverChannel = serverBootstrap.bind(tcpSocketAddress).sync().channel();
        System.out.println("Netty server started on port: " + tcpSocketAddress.getPort());
        serverChannel.closeFuture().sync();
    }
}
